package com.example.springlog.config.log;

import com.example.springlog.entity.DesensitiveRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description:
 * @Author: 刘超
 * @Date: 2023-06-08 10:18
 */
@Component
public class ApplicationConfig {
    @Autowired
    LoggerConfig loggerConfig;



    @PostConstruct
    public void init(){
        DesensitiveRule idcard = new DesensitiveRule("(\\d{18}$)|(\\d{17}(\\d|X|x))","6,14");
        DesensitiveRule phone = new DesensitiveRule("(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}","3,7");
        DesensitiveRule email = new DesensitiveRule("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*","@<(3,7)");
        List<DesensitiveRule> rules = new ArrayList<>(Arrays.asList(idcard,phone,email));
        loggerConfig.setRules(rules);
    }
}
